﻿using UnityEngine;
using System.Collections;

public class ShipController : MonoBehaviour {
	
	public float velocity = 1;
	
	public Transform shipModel;
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void FixedUpdate () {
				
		velocity += Input.GetAxis("Mouse ScrollWheel");
		
		transform.RotateAround(transform.position, transform.up,Input.GetAxis("Horizontal"));
		transform.RotateAround(transform.position, transform.right,Input.GetAxis("Vertical"));
		rigidbody.AddForce(transform.forward * velocity * 100);
		
		shipModel.transform.rotation = Quaternion.Slerp(shipModel.transform.rotation, transform.rotation * Quaternion.AngleAxis(30 * -Input.GetAxis("Horizontal"),Vector3.forward), Time.deltaTime*5);
		
		if(Input.GetKeyDown ("q")){
			rigidbody.AddForce(transform.right * -15000);
			shipModel.transform.rotation = transform.rotation * Quaternion.AngleAxis(-30,Vector3.forward);
		}
		
		if(Input.GetKeyDown ("e")){
			rigidbody.AddForce(transform.right * 15000);
			shipModel.transform.rotation = transform.rotation * Quaternion.AngleAxis(30,Vector3.forward);
		}
	}
}
